package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketOrder;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 付诚
 * @Date: 2024/5/21 14:12
 * @Description:
 */
@Service
public class WxUserServiceImpl implements WxUserService {

 @Autowired
 MarketOrderMapper marketOrderMapper;

 @Override
 public Map<String, Object> index(Integer id) {

  //存储数据
  Map<String,Integer> order = new HashMap<>();

  MarketOrderExample marketOrderExample1 = new MarketOrderExample();
  MarketOrderExample.Criteria criteria1 = marketOrderExample1.createCriteria();
  criteria1.andUserIdEqualTo(id);
  criteria1.andOrderStatusEqualTo((short) 401);
  criteria1.andDeletedEqualTo(false);
  List<MarketOrder> orderList1 = marketOrderMapper.selectByExample(marketOrderExample1);
  order.put("uncomment",orderList1.size());

  MarketOrderExample marketOrderExample2 = new MarketOrderExample();
  MarketOrderExample.Criteria criteria2 = marketOrderExample2.createCriteria();
  criteria2.andUserIdEqualTo(id);
  criteria2.andOrderStatusEqualTo((short) 101);
  criteria2.andDeletedEqualTo(false);
  List<MarketOrder> orderList2 = marketOrderMapper.selectByExample(marketOrderExample2);
  order.put("unpaid",orderList2.size());

  MarketOrderExample marketOrderExample3 = new MarketOrderExample();
  MarketOrderExample.Criteria criteria3 = marketOrderExample3.createCriteria();
  criteria3.andUserIdEqualTo(id);
  criteria3.andOrderStatusEqualTo((short) 301);
  criteria3.andDeletedEqualTo(false);
  List<MarketOrder> orderList3 = marketOrderMapper.selectByExample(marketOrderExample3);
  order.put("unrecv",orderList3.size());

  MarketOrderExample marketOrderExample4 = new MarketOrderExample();
  MarketOrderExample.Criteria criteria4 = marketOrderExample4.createCriteria();
  criteria4.andUserIdEqualTo(id);
  criteria4.andOrderStatusEqualTo((short) 201);
  criteria4.andDeletedEqualTo(false);
  List<MarketOrder> orderList4 = marketOrderMapper.selectByExample(marketOrderExample4);
  order.put("unship",orderList4.size());

  Map<String, Object> data = new HashMap<>();
  data.put("order",order);

  return data;
 }
}